package com.hanamaki.exception.demo02;

/**
 * @author hanamaki
 * @version 1.0
 * @date 2021/6/28 14:57
 */
public class Test {

    public static void main(String[] args) {
//        ArithmeticException
//        ArrayIndexOutOfBoundsException
//        AgeIllegalException

        try {
            setAge(199);
        } catch (AgeIllegalException e) {
            System.out.println(e.toString());
        }

    }

    public static void setAge(int age) throws AgeIllegalException {

        System.out.println("传递的年龄为：" + age);
        if (age < 1 || age > 100) {
            throw new AgeIllegalException(age);
        } else {
            System.out.println("OK");
        }



    }
}
